package com.diyunapp.xilinapp.me;

import android.content.Intent;
import android.os.Bundle;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.main.MainActivity;
import com.diyunapp.xilinapp.selfdefine.StatusBarFragmentActivity;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

import org.json.JSONException;
import org.json.JSONObject;

public class PhoneCer1Activity extends StatusBarFragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_email_cer1);
        getBindData();
    }
    private void getBindData() {
        String url=""+MainActivity.url+"act=goods&op=find_mobile_email&member_id="+MainActivity.myLogin.getMemberid()+"";
//        String url = "http://www.xilingou.com/mobile/index.php?act=goods&op=find_mobile_email&member_id="+id+"";
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(1000);
        http.send(HttpRequest.HttpMethod.POST, url,
                new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        String resultinfo = responseInfo.result;
//                        Log.i("zhangxiaoxidebug", "resultinfo=" + resultinfo);
                        try {
                            JSONObject resultObject = new JSONObject(resultinfo);
                            int result = resultObject.optInt("code");
//                            toast(String.valueOf(result));
                            if (result == 200) {
                                JSONObject recordObject = resultObject.optJSONObject("data");
                                String member_email = recordObject.optString("member_email");
                                String member_mobile = recordObject.optString("member_mobile");
                                int member_email_bind = recordObject.optInt("member_email_bind");
                                int member_mobile_bind = recordObject.optInt("member_mobile_bind");
                                 if(member_mobile_bind==1){
                                    Intent intent2 = new Intent();
                                    intent2.setClass(PhoneCer1Activity.this, EmailCer2Activity.class);
                                    intent2.putExtra("num",member_mobile);
                                    intent2.putExtra("type","手机号");
                                    startActivity(intent2);
                            }else if(member_mobile_bind==0) {
//                                    nextAct(PhoneCerActivity.class);
                                }

                            } else {
                                toast("当前暂无数据");
                            }
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            toast("查询失败");
                            e.printStackTrace();
                        }
                    }
                    @Override
                    public void onFailure(HttpException error, String msg) {
                        toast("请求失败");
                    }
                });
}
}
